home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94c.txt / 000038_kwalker@sirtur.premenos.com _Tue Dec 27 09:26:09 1994.msg < prev    next >
Internet Message Format  |  1995-02-09  |  4KB

  1. Received: from optima.CS.Arizona.EDU by cheltenham.CS.Arizona.EDU; Tue, 27 Dec 1994 10:33:28 MST
  2. Received: from gatekeeper.premenos.com by optima.CS.Arizona.EDU (5.65c/15) via SMTP
  3.     id AA14327; Tue, 27 Dec 1994 10:33:18 MST
  4. Received: from localhost (smap@localhost) by gatekeeper.premenos.com (8.6.5/8.6.5) id JAA12653 for <icon-group@cs.arizona.edu>; Tue, 27 Dec 1994 09:33:14 -0800
  5. Received: from sirtur.premenos.com(150.105.100.47) by mail.premenos.com via smap (V1.3mjr)
  6.     id sma012651; Tue Dec 27 09:33:04 1994
  7. Received: by sirtur.sirtur.premenos.com (5.x/SMI-SVR4)
  8.     id AA04590; Tue, 27 Dec 1994 09:26:09 -0800
  9. Date: Tue, 27 Dec 1994 09:26:09 -0800
  10. From: kwalker@sirtur.premenos.com (Ken Walker)
  11. Message-Id: <9412271726.AA04590@sirtur.sirtur.premenos.com>
  12. To: icon-group@cs.arizona.edu
  13. Subject: Re: DeMorgan's Law doesn't work
  14. X-Sun-Charset: US-ASCII
  15.  
  16. > From: MENGARINI@news1.delphi.com (MENGARINI@DELPHI.COM)
  17. > I needed to find the first filename of the form "w[0-9][0-9]" that was
  18. > not in use in either of 2 directories.  This code
  19. >    (  nn := (0 to 9) || (0 to 9)
  20. >    ,  not exists( downloadDir || "w" || nn )
  21. >    ,  not exists( targetDir   || "w" || nn )
  22. >    )|stop( "No names of the form w[0-9][0-9] were unused." )
  23. > works, but the separation of the 2 "not exists" calls is reminiscent
  24. > of Algol-family languages' need to code things like
  25. >    if importantNumber = 1 | importantNumber = 2
  26. > where Snobol-family languages could just test whether
  27. >    importantNumber = 1 | 2
  28. > Analogously, Icon should be able to factor out the 2 "not exists" calls.
  29. > But this
  30. >    (  nn := (0 to 9) || (0 to 9)
  31. >    ,  not exists( (downloadDir|targetDir) || "w" || nn )
  32. >    )|stop( "No names of the form w[0-9][0-9] were unused." )
  33. > doesn't work because DeMorgan's Law doesn't work:
  34. > if downloadDir || "w" || nn doesn't exist, exists() fails, not exists()
  35. > succeeds, & the expression succeeds, without ever testing whether
  36. > targetDir || "w" || nn exists.
  37.  
  38. The second example does work! When exists() fails, the alternation is
  39. resumed and the existance of the file in the other directory is tested.
  40.  
  41. The following program shows that DeMorgan's Law holds in Icon:
  42.  
  43. ********** Cut Here *********
  44.  
  45. # Demonstrate DeMorgan's Law using &null as false and 1 as true.
  46. #
  47. record pair(a,b)
  48.  
  49. procedure main()
  50.     local x
  51.  
  52.     #
  53.     # Print truth tables.
  54.     #
  55.     write("A    B    (not A) & (not B)    not (A | B)")
  56.     write("------------------------------------------")
  57.     every x := comb() do {
  58.         writes(format(x.a), "    ", format(x.b), "            ")
  59.         if ((not \x.a) & (not \x.b)) then
  60.             writes("T")
  61.         else
  62.             writes("F")
  63.     writes("                 ")
  64.         if not (\x.a | \x.b) then
  65.             write("T")
  66.         else
  67.             write("F")
  68.     }
  69.  
  70.     write()
  71.     write("A    B    (not A) | (not B)    not (A & B)")
  72.     write("------------------------------------------")
  73.     every x := comb() do {
  74.         writes(format(x.a), "    ", format(x.b), "            ")
  75.         if ((not \x.a) | (not \x.b)) then
  76.             writes("T")
  77.         else
  78.             writes("F")
  79.     writes("                 ")
  80.         if not (\x.a & \x.b) then
  81.             write("T")
  82.         else
  83.             write("F")
  84.     }
  85. end
  86.  
  87. #
  88. # comb() - produce all 4 pairs of "logical" values.
  89. #
  90. procedure comb()
  91.     suspend pair(1 | &null, 1 | &null)
  92. end
  93.  
  94. #
  95. # Convert a "logical" value to "T" or "F".
  96. #
  97. procedure format(x)
  98.     if \x then
  99.     return "T"
  100.     else
  101.     return "F"
  102. end